package com.ydc.ln.tutorial.clasler;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 爬虫工具类
 * 
 * <pre>
 * 依赖jar包
 * httpclient-4.1.2.jar
 * httpcore-4.1.2.jar
 * commons-logging-1.1.1.jar
 * </pre>
 * 
 * @author yangdc
 * @date 2012/01/16
 * 
 */
public class ClaslerUtil {
	
	
	/**
	 * 将文本内容保存到文件
	 * 
	 * @param content
	 * @param destFile
	 */
	public void saveToFile(String content, String destFile) {
		if (content == null) {
			return;
		}
		if (destFile == null || "".equals(destFile)) {
			return;
		}
		File file = new File(destFile);
		boolean fileFlag = true;
		if (!file.exists()) {
			try {
				fileFlag = file.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		if (fileFlag) {
			FileOutputStream fos = null;
			try {
				fos = new FileOutputStream(file);
				fos.write(content.getBytes());
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException ie) {
				ie.printStackTrace();
			} finally {
				if (fos != null) {
					try {
						fos.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
		}
	}
}
